package com.summer.safe.controller.system;

import com.summer.safe.base.Principal;
import com.summer.safe.config.properties.ConfigureProperties;
import com.summer.safe.config.properties.CustomProperties;
import com.summer.safe.system.entity.User;
import com.summer.safe.utils.ShiroUtils;
import com.summer.safe.utils.UserUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;

/**
 * 首页的Controller
 */
@Controller
public class IndexController {

    @Resource
    private ConfigureProperties configureProperties;
    @Resource
    private CustomProperties customProperties;


    @GetMapping("/index")
    public String index(Model model) {
        Principal principal = ShiroUtils.getPrincipal();
        if(principal==null){
            return "redirect:/login";
        }
        model.addAttribute("name",principal.getName());
        model.addAttribute("id",principal.getId());
        model.addAttribute("productName",configureProperties.getProductName());

        return "index.html";
    }




    @GetMapping("/index/main")
    public String home(Model model) {
        User user= UserUtils.getUser();
        model.addAttribute("name",user.getName());
        return "welcome.html";
    }






}
